import cPickle, os

class Preferences():
    def __init__(self, savePath='.'):
        self.__prefPath = savePath + '/prefs.pkl'
        if os.path.exists(self.__prefPath):
            temp = self.__loadPrefs(self.__prefPath)   # Unpickle preferences
            # Restore preferences #
            self.__windowSize = temp.getWindowSize()
        else:
            self.__windowSize = (800,600)
    
    def __loadPrefs(self, loadLocation):
        loadFile = open(loadLocation, 'rb')
        preferencesObject = cPickle.load(loadFile)
        loadFile.close()
        return preferencesObject
    
    def getWindowSize(self):
        return self.__windowSize
    
    def setWindowSize(self, newSize):
        self.__windowSize = newSize
        return True
    
    def savePrefs(self):
        saveFile = open(self.__prefPath, 'wb')
        cPickle.dump(self, saveFile)
        saveFile.close()
        return True